$("#btn-new_homework").click(function (){
    var fileObj = document.getElementById("question_file").files[0];
    var homework = new FormData();
    homework.append("userID", localStorage.getItem("userid"));
    homework.append("homework_subject", $("#homework_subject").val());
    homework.append("homework_question", $("#homework_question").val());
    if(fileObj){
        homework.append("with_file", "yes");
        homework.append("file", fileObj);
    }else{
        homework.append("with_file", "no");
    }
    var homeworkdata = homework;
   $.ajax({
       url: "/act_new_homework",
       type: "POST",
       data: homeworkdata,
       processData: false,
       contentType: false,
       cache: false,
       success: function(result){
           switch(result){
               case '0':
                   window.alert("上传失败");
                   break;
               case '1':
                   window.alert("上传成功");
                   break;
               case '4001':
                   window.alert("登录学号不能为空");
                   break;
               case '4002':
                   window.alert("登录密码不能为空");
                   break;
               case '4003':
                   window.alert("注册学号不能为空");
                   break;
               case '4004':
                   window.alert("注册密码不能为空");
                   break;
               case '4005':
                   window.alert("注册邮箱不能为空");
                   break;
               case '4006':
                   window.alert("注册邮箱格式不正确");
                   break;
               case '4007':
                   window.alert("注册姓名不能为空");
                   break;
               case '4008':
                   window.alert("登录用户名或密码错误");
                   break;
               case '4009':
                   window.alert("用户注册尚未通过");
                   break;
               case '4010':
                   window.alert("没有需要审批的注册申请者");
                   break;
               case '4011':
                   window.alert("没有激活用户");
                   break;
               case '4012':
                   window.alert("待删除的用户没有userID");
                   break;
               default:
                   window.alert("系统错误");
          }
       },
       error: function() {
           window.alert("服务器错误");
       }
   });
})